/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_BTREE_PAGES_DISPATCHERS_BUILDER_HPP
#define	_CUBEFS_CORE_BTREE_PAGES_DISPATCHERS_BUILDER_HPP

#include <cubefs/core/btree/pages/dispatchers/defs.hpp>
#include <cubefs/core/btree/pages/dispatchers/tools.hpp>
#include <cubefs/core/btree/pages/dispatchers/factory.hpp>
#include <cubefs/core/btree/pages/dispatchers/node_dispatcher.hpp>


namespace cubefs    {
namespace btree     {


using namespace cubefs::tools;
using cubefs::TypeList;

template <
    typename NodeTypesList,
    typename NodeBase,
    typename PageMgr,
    typename Txn,
    typename SuperType = EmptyType
>
class BTreeModelDispatchersBuilder: public SuperType {

    typedef typename Sorter<
                NodeDescriptorMetadata,
                LEVEL,
                true,
                NodeTypesList
    >::Result                                                                   NodeList;

    typedef typename NodeFilter<ValueOp<ROOT, EQ, bool, true>,  NodeList>::Result RootList;
    typedef typename NodeFilter<ValueOp<LEAF, EQ, bool, true>,  NodeList>::Result LeafList;
    typedef typename NodeFilter<ValueOp<LEAF, EQ, bool, false>, NodeList>::Result NonLeafList;
    typedef typename NodeFilter<ValueOp<ROOT, EQ, bool, false>, NodeList>::Result NonRootList;

public:

    typedef NodeDispatcherTool<NodeBase, NodeList>                              NodeDispatcher;
    typedef NodeDispatcherTool<NodeBase, RootList>                              RootDispatcher;
    typedef NodeDispatcherTool<NodeBase, LeafList>                              LeafDispatcher;
    typedef NodeDispatcherTool<NodeBase, NonLeafList>                           NonLeafDispatcher;
    typedef NodeDispatcherTool<NodeBase, NonRootList>                           NonRootDispatcher;

    typedef typename Node2NodeMapTool<NodeList, true>::Map                      Root2NodeMap;
    typedef typename Node2NodeMapTool<NodeList, false>::Map                     Node2RootMap;

    typedef NodeFactoryTool<NodeList, NodeBase, PageMgr, Txn>                   NodeFactory;
};
    
}
}

#endif //_CUBEFS_CORE_BTREE_PAGES_DISPATCHERS_BUILDER_HPP